package com.acwing.partition21;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/3/11 14:50
 */
public class AC2069网络分析_并查集 {

    private static final int N = 10010;
    //dist[i]表示以i为根节点的所有节点都需要加上的值
    private static int[] parent = new int[N], dist = new int[N];
    private static int n, m;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        for (int i = 1; i <= n; i++) parent[i] = i;
        while (m-- > 0) {
            ss = reader.readLine().split(" ");
            int op = Integer.parseInt(ss[0]), a = Integer.parseInt(ss[1]), b = Integer.parseInt(ss[2]);
            if (op == 1) {
                int pa = find(a), pb = find(b);
                if (pa != pb) {
                    dist[pa] -= dist[pb];
                    parent[pa] = pb;
                }
            } else {
                int pa = find(a);
                dist[pa] += b;
            }
        }
        for (int i = 1; i <= n; i++) {
            //如果当前节点是根节点，直接输出；如果不是，还需要加上根节点的值
            if (i == find(i)) writer.write(dist[i] + " ");
            else writer.write((dist[i] + dist[find(i)]) + " ");
        }
        writer.flush();
    }

    private static int find(int x) {
        //当前节点或者当前节点的父节点是根节点，直接返回
        if (x == parent[x] || parent[parent[x]] == parent[x]) return parent[x];
        int t = find(parent[x]);
        dist[x] += dist[parent[x]];
        return parent[x] = t;
    }
}
